package com.xl.utils.util.设计模式.工厂模式.简单工厂模式;

/**
 * @author xionglin
 * @date 2021/5/6 22:20
 * @Description 工厂类
 */
public class FruitFactory {
    public static Fruit getInstanceByName(String name){
        Fruit fruit = null;
        if("Apple".equals(name)){
            fruit =new Apple();
        } else if("Orange".equals(name)){
            fruit =new Orange();
        }else {
            throw new RuntimeException("创建对象错误!");
        }
        return fruit;
    }

    //测试
    public static void main(String[] args) {
        Fruit fruit = FruitFactory.getInstanceByName("Orange");
        fruit.myName();
    }
}
